//#include "StdAfx.h"
#include ".\..\lib\tedit.h"

TEdit g_edit;
bool TEdit::Create(HWND WindowsHwnd, HINSTANCE hInst)
{
	m_hwnd = CreateWindow("EDIT",
							NULL,
							WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_AUTOHSCROLL|ES_LEFT|ES_READONLY|ES_MULTILINE|ES_AUTOVSCROLL,
							x, y,
							w, h,
							WindowsHwnd,
							(HMENU)1004,
							hInst,
							NULL);
	if (m_hwnd == NULL)
		return false;
	return true;
}

int TEdit::setEdit(int x, int y, int w, int h)
{
	this->x = x;
	this->y = y;
	this->w = w;
	this->h = h;
	return 0;
}

bool TEdit::println(char * str)
{
	if (str == NULL)
		return false;
	int len = GetWindowTextLength(m_hwnd);
	SendMessage(m_hwnd, EM_SETSEL, len, len);
	SendMessage(m_hwnd, EM_REPLACESEL, 1, (LPARAM) str);
	char s[3] ={ 13,10, 0};
	SendMessage(m_hwnd, EM_REPLACESEL, 1, (LPARAM)s);
	return true;
}

bool TEdit::println(const char * str)
{
	if (str == NULL)
		return false;
	int len = GetWindowTextLength(m_hwnd);
	SendMessage(m_hwnd, EM_SETSEL, len, len);
	SendMessage(m_hwnd, EM_REPLACESEL, 1, (LPARAM) str);
	char s[3] ={ 13,10, 0};
	SendMessage(m_hwnd, EM_REPLACESEL, 1, (LPARAM)s);
	return true;
}

bool TEdit::print(char * str)
{
	if (str == NULL)
		return false;
	int len = GetWindowTextLength(m_hwnd);
	SendMessage(m_hwnd, EM_SETSEL, len, len);
	SendMessage(m_hwnd, EM_REPLACESEL, 1, (LPARAM) str);
	return true;
}